package com.cykj.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * Project:jx2503fs
 * Package:com.cykj.config
 *
 * @Description:
 * @Author:其一
 * @CreateTime: 2025-07-28-16-27
 */
@Configuration
public class RedisRateConfig {

    @Bean
    public KeyResolver userKeyResolver() {
        KeyResolver keyResolver = new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                // 写过滤规则了，如果可以根据ip地址进行过滤
                String ip = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
                System.out.println(ip);
                return Mono.just(ip);
            }
        };
        return keyResolver;
    }
}
